#!/usr/bin/env python

import os
import urllib
import json

from google.appengine.api import users
from google.appengine.ext import ndb
from baseClasses import BaseRequestHandler

import jinja2
import webapp2

JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), 'markup/project')),
    extensions=['jinja2.ext.autoescape'],
    autoescape=True)

class ProjectList(BaseRequestHandler):
    def get(self):
        self.response.write('Project List!')
        template = JINJA_ENVIRONMENT.get_template('index.html')
        self.session[self.app_config['SESSION']['ID']] = 'bar'
        self.response.set_cookie(self.app_config['COOKIES']["AUTHENTICATION"], 'YAHOO', max_age=360, path='/')
        #self.template_values["env"] = os.environ
        #self.template_values["AUTH"] = self.app_config['COOKIES']["AUTHENTICATION"]
        
        self.response.write(template.render(self.template_values))

class DummyPage(webapp2.RequestHandler):
    def get(self):
        self.response.set_cookie('APP_AUTH', 'YAHOO', max_age=360, path='/')
        self.response.write('Project List!')
         
         
config = {}
config['webapp2_extras.sessions'] = {
    'secret_key': 'some-secret-key',
}

"""ZX: 
    It is recommended that the routing urls have (?i) to make it case-insensitive.
    Routing urls should end with slash (/).
    If there's no slash, browser (eg Google Chrome) might treat it as a document 
    and perform search instead of routing it.
"""
app = webapp2.WSGIApplication([
    #(r'(?i)^/projects/(\w+)*$', ProjectsPageHandler),
    (r'(?i)^/project/$', ProjectList)
], debug=True, config=config)

